import os

from constants import AlgoType
from data_process.feature_algorithm.MultiDopplerAlgorithm import MultiDopplerAlgorithm
from data_process.feature_algorithm.SingleDopplerAlgorithm import SingleDopplerAlgorithm
from utils.file_util import CreateMap


class DataGenerator:

    def __init__(self, wavPath, params):
        self.wavPath = wavPath
        self.params = params
        self.rootPath = params.rootPath
        self.vocabPath = params.vocabPath
        self.innerDirName = params.innerDirName
        self.algoType = params.algoType

    def getLabel(self):
        s2lDict, l2sDict = CreateMap(self.vocabPath)
        self.wavPath = self.wavPath.replace(os.sep, '/')
        pathClip = self.wavPath.split('/')
        word = pathClip[-1].split('_')[0]
        sinLabel = s2lDict[word]
        return sinLabel

    def createdata(self):
        print(self.wavPath)
        if self.algoType == AlgoType.SINGLE_DOPPLER:
            sinFeature = SingleDopplerAlgorithm(self.wavPath, self.params).createFeature()
        elif self.algoType == AlgoType.MULTI_DOPPLER:
            sinFeature = MultiDopplerAlgorithm(self.wavPath, self.params).createFeature()
        else:
            raise ValueError
        sinLabel = self.getLabel()
        return sinFeature, sinLabel
